begintownscript;
variables;
short choice,i,tick1,tick2,reset,x,y;
body;
beginstate init_state;
	if(get_flag(8,7) == 1) {
		set_terrain(46,43,445);
		set_terrain(46,39,445);
		set_terrain(54,38,446);

		set_terrain(47,43,444);
		set_terrain(47,39,444);
		set_terrain(53,38,444);

		set_terrain(48,38,0);
		set_terrain(48,41,0);
		set_terrain(50,47,0);
}
	reset = (get_current_tick());
break;

beginstate start_state;
	if(get_flag(8,6) == 1) {
		x = 47;
			while (x <=  53) {
				y = 33;
				while (y <= 48) 
				{	set_floor(x,y,98);
					y = y + 1; }
				x = x + 1; }
				set_flag(8,6,0);
}
if(get_flag(8,7) == 0)
	if(get_terrain(47,43) == 444)
		if(get_terrain(47,39) == 444)
			if(get_terrain(53,38) == 444) {
				message_dialog("You slide the last barricade in place. The path is now clear for your party to join you.","");
				set_flag(8,7,1); }

	if(get_terrain(47,43) == 444)
		set_terrain(46,43,445);	
	if(get_terrain(47,39) == 444)
		set_terrain(46,39,445);
	if(get_terrain(53,38) == 444)
		set_terrain(54,38,446);	
	if(get_flag(8,2) == 1) {
		if(is_combat() == 1) {
			i = 0;
			while(char_ok(i) == 0)
				{ i = i + 1; }
			put_straight_zap(char_loc_x(6),char_loc_y(6),char_loc_x(i),char_loc_y(i),5);
			put_effect_on_char((i),1,5,0);
			run_animation_sound(51);
			kill_char(i,2,0);
			message_dialog("You draw your swords and charge. The golems spot you easily, and kill you in seconds.",""); }

////GOLEM 2/////
if(get_terrain(53,38) != 444) {
	if(get_flag(8,3) == 0)
		{	tick1 = get_current_tick();
			set_flag(8,3,1); }
		if(get_flag(8,3) == 1)
			if((get_current_tick() - tick1) >= 4)
			{	set_character_facing(8,6);
				set_terrain(54,38,446);
				force_instant_terrain_redraw();
				tick1 = get_current_tick();
				set_flag(8,3,2); }
		if(get_flag(8,3) == 2)
			if((get_current_tick() - tick1) >= 4)
			{	set_character_facing(8,2);
				set_terrain(54,38,23);
				force_instant_terrain_redraw();
				tick1 = get_current_tick();
				set_flag(8,3,1); }
}
///GOLEM 3////

if(get_terrain(47,39) != 444) {
	if(get_flag(8,4) == 0)
		{	tick2 = get_current_tick() + 2;
			set_flag(8,4,1); }
		if(get_flag(8,4) == 1)
			if((get_current_tick() - tick2) >= 4)
			{	set_character_facing(9,2);
				set_terrain(46,39,445);
				force_instant_terrain_redraw();
				tick2 = get_current_tick();
				set_flag(8,4,2); }
		if(get_flag(8,4) == 2)
			if((get_current_tick() - tick2) >= 4)
			{	set_character_facing(9,6);
				set_terrain(46,39,25);
				force_instant_terrain_redraw();
				tick2 = get_current_tick();
				set_flag(8,4,1); }
}


}
break;


beginstate exit_state;
break;

beginstate 10;
	move_to_new_town(4,15,44);
break;

beginstate 11;
	move_to_new_town(4,15,23);
break;

beginstate 12;
if(get_flag(8,7) == 0) {
	reset_dialog();
	add_dialog_str(0,"You look out over this hallway hand your heart sinks. Windows are spaced out across, with golems standing behind each one. You doubt that your entire party could make it across, but one man might be able to make it, weaving through.",0);
	add_dialog_str(1,"There are several baricades situated in the hallway, if you are fast and crafty, you can make it across.",0);
	add_dialog_str(2,"Would you like to send your first character in?",0);
	add_dialog_choice(0,"Yes.");
	add_dialog_choice(1,"No.");
	choice = run_dialog(1);
	if(choice == 2) {
	block_entry(1);
	message_dialog("You turn back.","");
	end(); }
	if(choice == 1) {
		i = 0;
		while(char_ok(i) == 0)
			{ i = i + 1; }
		change_custom_abil_uses(0,0,1);
		change_custom_abil_uses(1,0,1);
		change_custom_abil_uses(2,0,1);
		change_custom_abil_uses(3,0,1);
		change_custom_abil_uses(0,1,1);
		change_custom_abil_uses(1,1,1);
		change_custom_abil_uses(2,1,1);
		change_custom_abil_uses(3,1,1);
		split_off_one_char(50,48,0,i);
		set_flag(8,2,1);
		set_ticks_forward(-1 * (reset));
		block_entry(1);
			reset_dialog();
			add_dialog_str(0,"The barricades in the hallway will allow you to bypass the golem sentries. If you are spotted, you will have one move before you are shot and killed.",0);
			add_dialog_str(1,"Some of the sentries will turn their backs, use this and your ability to move the barricades to navigate. Your goal is to push a barricade up against each window, allowing your party to join you safely.",0);
			add_dialog_str(2,"You will be able to use your special abilities to give yourself advantages. You can toggle full view mode, when on you can see over the barricades to watch the sentries.",0);
			add_dialog_str(3,"You can also use your special ability to toggle sight trace. When on, the floors will light up wherever a sentry can see.",0);
			add_dialog_str(4,"DO NOT swap your character around as long as you are in split party mode. DO NOT enter combat mode or you will be killed.",0);}
			add_dialog_choice(0,"OK");
			choice = (run_dialog(1));
			if(choice == 1)
				end(); }
break;

beginstate 13;
if(get_flag(8,8) == 1)
	end();
	if(get_flag(8,7) == 1)
	{	message_dialog("You should meet the rest of your party at the end of the hallway.","");
		block_entry(1);
		end(); }
	reset_dialog();
	add_dialog_str(0,"Would you like to rejoin your party?",0);
	add_dialog_choice(0,"No.");
	add_dialog_choice(1,"Yes.");
	choice = run_dialog(1);
	if(choice == 1)
		block_entry(1);
	if(choice == 2) { 
		i = 0;
		while(char_ok(i) == 0)
			{ i = i + 1; }
		if(get_flag(8,7) == 0)
		{	x = 47;
			while (x <=  53) {
				y = 33;
				while (y <= 48) 
				{	set_terrain(x,y,0);
					y = y + 1; }
				x = x + 1; }
		set_terrain(46,43,25);
		set_terrain(46,39,25);
		set_terrain(54,38,23);		
		set_terrain(48,38,444);
		set_terrain(48,41,444);
		set_terrain(50,47,444); }
		set_flag(8,6,0);
		set_flag(8,4,0);	
		change_custom_abil_uses(0,0,-1);
		change_custom_abil_uses(1,0,-1);
		change_custom_abil_uses(2,0,-1);
		change_custom_abil_uses(3,0,-1);
		change_custom_abil_uses(0,1,-1);
		change_custom_abil_uses(1,1,-1);
		change_custom_abil_uses(2,1,-1);
		change_custom_abil_uses(3,1,-1);
		reunite_party();
		teleport_party(50,55,1);
		set_total_visibility(0);
		set_ticks_forward(reset);
		set_flag(8,1,0);
		set_flag(8,2,0);
		set_flag(8,5,0); }
break;

beginstate 14;
if(get_flag(8,8) == 0)
{	if(get_flag(8,7) == 0) {
		message_dialog("Where are you going? You need to block up the remaining windows first.","");
		block_entry(1); }
	else { 
	message_dialog("Your party safely rejoins you, with that obstacle out of the way its now time to continue your journey through the tower.","");
	reunite_party();
	teleport_party(50,31,1);
	change_custom_abil_uses(0,0,-1);
	change_custom_abil_uses(1,0,-1);
	change_custom_abil_uses(2,0,-1);
	change_custom_abil_uses(3,0,-1);
	change_custom_abil_uses(0,1,-1);
	change_custom_abil_uses(1,1,-1);
	change_custom_abil_uses(2,1,-1);
	change_custom_abil_uses(3,1,-1);
	set_total_visibility(0);
	set_ticks_forward(reset);
	set_flag(8,1,0);
	set_flag(8,2,0);
	set_flag(8,5,0);
	set_flag(8,8,1); }
}
break;

beginstate 15;
	move_to_new_town(9,24,38);
break;
